package com.opal.config;

import org.activiti.engine.*;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

@Configuration
public class ActivitiConfig {

    @Bean(name = "processEngine")
    public ProcessEngine processEngine(@Qualifier("mysqlTransactionManager") DataSourceTransactionManager dstm, @Qualifier("mySqlOpalDataSource") DataSource dataSource){
        SpringProcessEngineConfiguration secf= new SpringProcessEngineConfiguration();
        secf.setTransactionManager(dstm);                   //事务
        secf.setDataSource(dataSource);                     //数据源
        secf.setDatabaseSchemaUpdate("true");

        secf.setDbIdentityUsed(false); 	//这段代码表示是否使用activiti自带用户组织表,如果不是,这里为false,这样启动就不用去检查用户组织表是否存在。
        secf.setMailServerHost("smtp.163.com");
        secf.setMailServerPort(465);
        secf.setMailServerUsername("18318831175@163.com");
        secf.setMailServerPassword("MTPNSBYLWBFMIXHR");
//        secf.setMailServerHost("smtp.exmail.qq.com");
//        secf.setMailServerPort(465);
//        secf.setMailServerUsername("wwl@opalhk.com");
//        secf.setMailServerPassword("Op2000-+");
        //secf.setMailServerPassword("QJTOXACAJYIEJPYA");
        secf.setMailServerUseSSL(true);

        ProcessEngine processEngine = secf.buildProcessEngine();
        return processEngine;
    }

    @Bean
    public RepositoryService repositoryService(ProcessEngine processEngine) {
        return processEngine.getRepositoryService();
    }

    @Bean
    public RuntimeService runtimeService(ProcessEngine processEngine) {
        return processEngine.getRuntimeService();
    }

    @Bean
    public TaskService taskService(ProcessEngine processEngine) {
        return processEngine.getTaskService();
    }

    @Bean
    public HistoryService historyService(ProcessEngine processEngine) {
        return processEngine.getHistoryService();
    }

    @Bean
    public ManagementService managementService(ProcessEngine processEngine) {
        return processEngine.getManagementService();
    }

    @Bean
    public IdentityService identityService(ProcessEngine processEngine) {
        return processEngine.getIdentityService();
    }

}
